package com.intelligence.device.manager.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.intelligence.device.manager.service.DeviceLogService;
import com.intelligence.entity.pojo.DeviceLog;
import com.intelligence.entity.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 通用的增删改页面
 * @Author : RulerWood
 * @Data : 2024/6/3 - 15:56
 */
@RestController
@RequestMapping("/device/deviceLog")
public class DeviceLogController {

    @Autowired
    private DeviceLogService deviceLogService;

    /**
     * 获取数据列表
     * @param offset    当前页数
     * @param pageSize  每页条目数
     * @return
     */
    @GetMapping("/listDeviceLog")
    public Result<Page<DeviceLog>> list(@RequestParam(value = "offset", defaultValue = "1") Integer offset,
                                        @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
        return Result.build(deviceLogService.page(new Page<>(offset, pageSize)), 200, "获取设备日志列表成功");
    }

    /**
     * 获取单个对象
     * @param id    对象主键
     * @return
     */
    @GetMapping("/getOneDeviceLog/{id}")
    public Result getOneDeviceLog(@PathVariable(value = "id") Integer id) {
        return Result.build(deviceLogService.getById(id), 200, "获取设备日志成功");
    }



    /**
     * 数据的新增
     * @param deviceLog 保存对象
     * @return
     */
    @PostMapping("/saveDeviceLog")
    public Result saveDeviceLog(@RequestBody DeviceLog deviceLog) {
        deviceLogService.save(deviceLog);
        return Result.build(null, 200, "保存设备日志成功");
    }

    /**
     * 数据的修改
     * @param deviceLog 修改对象
     * @return
     */
    @PutMapping("/updateDeviceLog")
    public Result updateDeviceLog(@RequestBody DeviceLog deviceLog) {
        deviceLogService.updateById(deviceLog);
        return Result.build(null, 200, "更新设备日志成功");
    }

    /**
     * 删除某条数据
     * @param id    数据主键
     * @return
     */
    @DeleteMapping("/deleteDeviceLog/{id}")
    public Result deleteDeviceLog(@PathVariable(value = "id") Integer id) {
        deviceLogService.removeById(id);
        return Result.build(null, 200, "删除设备日志成功");
    }

}
